/**
 * Copyright (C), 2018-2020, 飞尔智能有限公司
 * FileName: UserConsumerService
 * Author:   杨乐
 */
package com.yangle.eurekaclientproducter;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.yangle.feign.User;
import com.yangle.feign.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @description:
 * @Author 杨乐
 * @Date 2020/2/3 21:17
 * @Version 1.0
 **/
@RestController
@RequestMapping("consumer")
public class UserConsumerService {
    @Autowired
    private UserFeign userFeign;
    @GetMapping("/user/get")
    @HystrixCommand(fallbackMethod = "getUserFallback")
    public User getUser(@RequestParam("name") String name){
        return userFeign.getUser(name);
    }
    //失败回调
    public User getUserFallback(@RequestParam("name") String name){
        User user=new User();
        user.setName(name);
        user.setEmail("调用失败");
        return user;
    }

    @GetMapping("/user/getMap")
    public User getUser(@RequestParam Map<String,String> param){
        return userFeign.getUser(param);
    }

    @PostMapping("/user/add")
    public User addUser(@RequestParam("name") String name, @RequestParam("email")String email){
        return userFeign.addUser(name,email);
    }

    @PostMapping("/user/addBody")
    public User addUser(@RequestBody User user){
        return userFeign.addUser(user);
    }
}
    
